package it.intecs.pisa.smarcos.sounds;

import it.intecs.pisa.smarcos.R;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;

public class SoundEffects implements OnLoadCompleteListener {
	protected static SoundEffects instance=null;
	protected boolean isReady=false;
	protected SoundPool pool=null;
	protected int beepId;
	
	public SoundEffects(Context context)
	{
		pool=new SoundPool(1,AudioManager.STREAM_MUSIC,0);
		pool.setOnLoadCompleteListener(this);
		beepId=pool.load(context,R.raw.beep, 1);
	}
	
	public static SoundEffects getInstance(Context con)
	{
		if(instance==null)
			instance=new SoundEffects(con);
		
		return instance;
	}
	
	public void beep()
	{
		playSound(beepId);
	}

	protected void playSound(int id)
	{
		if(isReady)
			pool.play(id, 0.5f, 0.5f, 0, 0, 1.0f);
	}
	
	public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
		isReady=true;
	}
}
